package com.hudsonmq.spring.impl.produce.impl;


import com.hudson.codec.domain.Message;
import com.hudson.common.domain.Duration;
import com.hudson.core.concurrent.CallBack;
import com.hudsonmq.spring.impl.produce.RemoteClient;
import com.hudsonmq.spring.impl.produce.helper.SendMessageHelper;
import com.hudsonmq.spring.impl.produce.helper.SendMessageSyncHelper;
import com.hudsonmq.spring.utils.SnowflakeIdGeneratorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * todo:需要解决 broker 真没这个topic的话 怎么默认发送到 broker 让 broker 创建topic 和 队列
 */
public class AsyncRemoteClient implements RemoteClient {
    private static final Logger logger = LoggerFactory.getLogger(AsyncRemoteClient.class);


    @Override
    public Boolean send(Message message, CallBack callBack) {
        long messageId = SnowflakeIdGeneratorUtil.getMessageId();

        SendMessageHelper.sendMessage(messageId, message, callBack);

        return true;
    }

    @Override
    public Boolean relaySend(Message message, CallBack callBack, Duration duration) {
        long messageId = SnowflakeIdGeneratorUtil.getMessageId();
        SendMessageHelper.sendRelayMessage(messageId, message, duration);

        SendMessageSyncHelper.put(messageId, callBack);

        return true;
    }
}